<?
ini_set('display_errors', 0);
error_reporting(E_ALL ^ E_NOTICE);
//require('config.php');
require('config-local.php');
require('constants.php');
require('rendering.php');
require('post_convert.php');
session_start();
//This function securing the posted variable
function S($pValue)
{
	//echo 'posted value '.$pValue;
	$checked = str_ireplace("script", 'zzz',$pValue);
	$checked = str_ireplace('iframe', 'zzz',$pValue);
	
	return htmlspecialchars($checked);
	//return $checked;
}
//Check Null Boolean
function CN_B($pValue)
{
if($pValue == '' or $pValue == 'undefined')
{
	$pValue = '0';
}
return $pValue;
}
//Check Null String/Varchar
function CN_S($pValue)
{
	
if($pValue == "")
{
	$checked= "''";
}
else
{
	//$pValue = "'".mysql_real_escape_string($pValue)."'";
	//This checking string for injetions workds (INSERT, UPDATE, DELTE, ALTER, DROP)
	$checked = str_ireplace('INSERT', 'INSERT.',$pValue);
	$checked = str_ireplace('UPDATE', 'UPDATE.',$pValue);
	$checked = str_ireplace('DELETE', 'DELETE.',$pValue);
	$checked = str_ireplace('ALTER', 'ALTER.',$pValue);
	$checked = str_ireplace('DROP', 'DROP.',$pValue);
	$checked = str_ireplace('<script>', '<!--',$pValue);
	$checked = str_ireplace('</script>', '-->',$pValue);
	$checked = str_ireplace('<iframe', '--',$pValue);
	$checked = "'".mysql_real_escape_string(trim($checked))."'";
}
return $checked;
}
//Check Null Number(Float)
function CN_N($pValue)
{
if($pValue == '')
{
	$pValue = 0.0;
}
else
{
	$pValue = "".$pValue."";
}
return $pValue;
}
//Check Null Number(Int)
function CN_I($pValue)
{
if($pValue == '')
{
	$pValue = 0;
}
else
{
	$pValue = "".$pValue."";
}
return $pValue;
}
//Check Password or make it
function CN_P($pValue)
{
if($pValue == '')
{
	$pValue = "''";
}
else
{
	$pValue = "'".md5($pValue)."'";
}
return $pValue;
}
//PROTECTING FROM UN AUTHORIZE ACCESS
function protect()
{
	if(!isset($_COOKIE['memberid']))
		header("Location: login.php");
}

function protect_alreadyLoggedIn()
{
	if(isset($_COOKIE['memberid']))
		header("Location: ".SITEURL."settings.php");
}

function protect_admin()
{
	if(!isset($_COOKIE['admin']))
	{
			header("Location: index.php");
	}
}


function getImagePath($pImageName)
{
	$img_src = substr($pImageName,0,3);
	$img_src = ($img_src == 'URL') ? substr($pImageName,4) : fullURL('productimages/thumb/'.$pImageName);
	
	return $img_src;
}

function createImageLink($pIcon, $pLink, $pToolTip = null)
{
	//echo $pIcon;
	$iconPath = SITEURL.'images/'.$pIcon;
	//echo $iconPath;
	$html = '<a href="'.$pLink.'"><img src="'.$iconPath.'" alt="'.$pToolTip.'" border=0 />'.$pToolTip.'	</a>';
				
	return $html;
} 


function createIconLink($pIcon, $pLink, $pToolTip = null, $pObjectID = null)
{
	//echo $pIcon;
	$iconPath = SITEURL.'iconset/'.$pIcon;
	//echo $iconPath;
	$html = '<a href="'.$pLink.'"><img id="'.$pObjectID.'" src="'.$iconPath.'" alt="'.$pToolTip.'" border=0 /></a>';
				
	return $html;
}

//Check if Seller has balance left
function protect_accountBalance($pBalance)
{
	//echo 'balance '.$pBalance;
	if($pBalance <= 0 )
	{
		
		return 'balanceout';
	}
	else
	{
		return 'item';
	}
}
//USA DATE FORAMT
function US_Date($pDate)
{
	$dt = date('m-d-Y',strtotime($pDate));
	return $dt;
}

function US_Date_Mail($pDate)
{
	$dt = date('M-d',strtotime($pDate));
	return $dt;
}

function US_Date_Mail_Detail($pDateTime)
{
	$dt = date('M . d, Y',strtotime($pDateTime));
	return $dt;
}

function US_Time_Mail($pDateTime)
{
	$dt = date('H:i a',strtotime($pDateTime));
	return $dt;
}

//USA TIME FORAMT
function US_DateTime($pDateTime)
{
	$dt = date('m-d-Y h:m:s',strtotime($pDateTime));
	return $dt;
}

//Just Month
function US_Month($pDate)
{
	$dt = date('M-y',strtotime($pDate));
	return $dt;
}

function mysql_Date($pDate)
{
	$dt = date('Y-m-d',strtotime($pDate));
	return "'".$dt."'";
}
//GETTING SHIPPING RATE e.g. SHIPPINGUS, SHIPPINGCANADA OR SHIPPING WORLDWIDE
function getShippingRate($pShippingTo)
{
	
	if($pShippingTo == 'US')
	{
		$shippingrate = 'SHIPPINGUSA1;SHIPPINGUSA2';
	}
	elseif(pShippingTo == 'CA')
	{
		$shippingrate = 'SHIPPINGCANADA1;SHIPPINGCANADA2';
	}
	else
	{
		$shippingrate = 'SHIPPINGWW1;SHIPPINGWW2';
	}
	
	return $shippingrate;
}
//CALCULATING SHIPPING FOR orderdetail.php (clsForm.GridBox_OrderDetail)
function calculateShipping($pQty,$pShipping1,$pShipping2)
{
	/*echo '<br />Qty = '.$pQty;
	echo '<br />pShipping1 = '.$pShipping1;
	echo '<br />pShipping2 = '.$pShipping2;
	exit;*/

	if($pQty > 1)
	{
		$shipping = ($pShipping1 + ($pShipping2 * ($pQty -1)));
	}
	else
	{
		$shipping = $pShipping1;
	}
	
	return $shipping;
}
function fixLengthWords($pStr,$pLength)
{
		$length = $pLength; // The number of words you want
	
		$text = strip_tags($pStr);
		/*echo $text;
		exit;*/
		$words = explode(' ', $text); // Creates an array of words	
		$words = array_slice($words, 0, $length);
		$str = implode(' ', $words);
		
		$str .= (count($words) < $pLength) ? '' : '...';
		
		return $str;
}
//================= THIS FUNCTINO IS CREATING URLs for ITEM DETAIL =====================
function itemDetailURL($pStoreID,$pItemID)
{
	$url = SITEURL."stores.php?storeid=$pStoreID&amp;itemid=$pItemID&amp;page=itemdetail";
	return $url;
}
//================= THIS FUNCTINO IS CREATING URLs for STORE DETAIL =====================
function storeDetailURL($pStoreID)
{
	$url = SITEURL."stores.php?storeid=$pStoreID";
	return $url;
}
//================== THIS FUNCTION WILL LOAD THE PAGE OF STORES BASED ON $_REQUEST['pCurrentPage'] variable
function getPageName($pPage)
{
	switch($pPage)
	{
	
		case "home":
			return 'home.php';
			break;
		
		case 'itemdetail':
			return 'itemdetail.php';
			break;
			
		default:
			return 'home.php';
			break;
			
	}
}
//=======================EMAIL RENDERING ==============================

function renderSignupEmail($uName, $sessionid)
{
	$html = '<html>
			<body style="font-family:Verdana; font-size:14px;">
			Dear '.$uName.'<br />
				
				<p>Your registration has been completed successfully with us. You need to activate your account by click following link.</p>
				
	<a href="'.SITEURL.'processing/REGISTER.php?act=activate&token='.$sessionid.'" target="_blank">
	Activate My Account</a>
	<br />
	<br />

	
	Thanks<br />

	Team '.SITEURL.'
	</body>
	</html>';
	
	return $html;
}

function sendMail($pTo, $pSubject, $pMessage, $pFrom = MALLADMIN)
{
	$headers  = "MIME-Version: 1.0\r\n";
    $headers .= "Content-type: text/html; charset=iso-8859-1\r\n";
    $headers .= "From: $pFrom\r\n";
	
	//echo $pMessage;
	mail($pTo, $pSubject, $pMessage, $headers);
}

function generatePassword($length=9, $strength=0) {
	$vowels = 'aeuy';
	$consonants = 'bdghjmnpqrstvz';
	if ($strength & 1) {
		$consonants .= 'BDGHJLMNPQRSTVWXZ';
	}
	if ($strength & 2) {
		$vowels .= "AEUY";
	}
	if ($strength & 4) {
		$consonants .= '23456789';
	}
	if ($strength & 8) {
		$consonants .= '@#$%';
	}
 
	$password = '';
	$alt = time() % 2;
	for ($i = 0; $i < $length; $i++) {
		if ($alt == 1) {
			$password .= $consonants[(rand() % strlen($consonants))];
			$alt = 0;
		} else {
			$password .= $vowels[(rand() % strlen($vowels))];
			$alt = 1;
		}
	}
	return $password;
}

function renderRecoveryPassword($pFlag, $pPassword)
{
	$html = '<html>
			<body style="font-family:Verdana; font-size:14px;">
			Hi<br />';
			
		if($pFlag){
			$html .= '<p>Upon your request your Password is reset. Here below is your new password:</p>
				<strong>Password : '.$pPassword.'</script><br />
				<a href="'.SITEURL.'login.php" target="_blank">Login</a>';
		}
		else
		{
			$html .= '<h3>Ooops!</h3>
					<p>Your email does not exist in our records. Please Signup yourself.</p>
					<a href="'.SITEURL.'register.php" target="_blank">Signup Now</a>';
		}

	$html .= '<br /><br />

	
	Thanks<br />

	Team '.SITEURL.'
	</body>
	</html>';
	
	return $html;
}

function renderNotification($pText)
{
	$html = '<div class="ui-widget">
			<div class="ui-state-highlight ui-corner-all" style="margin-top: 20px; padding: 0 .7em;"> 
				<p><span class="ui-icon ui-icon-info" style="float: left; margin-right: .3em;"></span>
				'.$pText.'
				</p>
			</div>
			</div>';
	return $html;
}
//======================= STORE BANNER HTML ==============================
function storeBanner($pBannerName,$pAlt)
{
	$bannerHTML = '<a href="'.urlStore($pAlt).'">		
						<img border=0 src="'.SITEURL.'storebanners/'.$pBannerName.'" alt="'.$pAlt.'" />
						</a>';
	return $bannerHTML;
}
//======================= SHIPPING METHOD HTML ==============================
function shippingMethod(&$ItemArray)
{
	//print_r($ItemArray);
	//echo ceil($ItemArray[0][SHIPPINGWW1]);
	$strHTML = '';
	if($ItemArray[0][SHIPPINGCANADA1] != '' and ceil($ItemArray[0][SHIPPINGCANADA1]) != 0)
	{
		$strHTML = "<tr><td>Canada</td><td>".$ItemArray[0][SHIPPINGCANADA1]."</td><td>".$ItemArray[0][SHIPPINGCANADA2]."</td></tr>";
	}
	
		if($ItemArray[0][SHIPPINGUSA1] != '' and ceil($ItemArray[0][SHIPPINGUSA1]) != 0)
	{
		$strHTML .= "<tr><td>United States</td><td>".$ItemArray[0][SHIPPINGUSA1]."</td><td>".$ItemArray[0][SHIPPINGUSA2]."</td></tr>";
	}
		if($ItemArray[0][SHIPPINGWW1] != '' and ceil($ItemArray[0][SHIPPINGWW1]) != 0)
	{
		$strHTML .= "<tr><td>Worldwide Else</td><td>".$ItemArray[0][SHIPPINGWW1]."</td><td>".$ItemArray[0][SHIPPINGWW2]."</td></tr>";
	}
	echo $strHTML;
	
}
function loadItemThumbs(&$ItemImageArray)
{
	for($i=0; $i<count($ItemImageArray); $i++)
	{
		echo '<tr><td>
				<div id="sideThumb">
            <img  name="'.$ItemImageArray[$i][IMAGENAME].'"
            		id="'.$i.'" 
            		src="'.fullURL('productimages/thumb/'.$ItemImageArray[$i][IMAGENAME]).'" 
            		onclick="swapImage(this.name);" />
            </div>
				</tr></td>';
	}
}
//======================= STORE MENU HTML ==============================
function loadStoreMenu($pStoreMenu,$pIsEbayExist, $pStoreName=null)
{
	echo '<ul>';
	//print_r($store->storeMenu);
	for($i=0; $i<count($pStoreMenu); $i++)
	{
			echo '<li>
			<a href="http://'.$_SERVER['HTTP_HOST'].'/stores.php?pgid='.$pStoreMenu[$i][ID].'">'.$pStoreMenu[$i][NAME].'</a>
			</li>';
   }
	
	if($pIsEbayExist)
	{	
		//echo 'root '.$_SERVER['HTTP_HOST'];
		echo '<li><a href="http://'.$_SERVER['HTTP_HOST'].'/stores.php?type=ebay">myEbay</a></li>';
	}
	
	echo '<li>
			<a href="'.urlStore($pStoreName).'/RSS/?storeid=63">
			<img border=0 src="'.fullURL('images/feedback-icon.jpg').'" alt="Feeds" />
			</a></li>';
	echo '</ul>';
}
function renderCartItem($arrCartItem,$pImage, &$pSubTotal)
{
	
   $total = round(($arrCartItem[QUANTITY] * $arrCartItem[PRICE]),2);
	$url = "processing/stores_processing.php?act=del&amp;cartid=$arrCartItem[ID]";
	echo '<tr>
         <td align="center"><img src="productimages/thumb/'.$pImage.'" alt="'.$arrCartItem[NAME].'" /><br />
			<a href="'.$url.'"><img border=0 src="images/delete.png" style="width:24px; height:24px;" /></a>
			</td>
         <td align="center">'.$arrCartItem[NAME].'</td>
         <td align="center">
			<input id="'.$arrCartItem[NAME].'" style="width:20px;text-align:center;" type="text" name="quantity" value="'.$arrCartItem[QUANTITY].'" />
			
			<script type="text/javascript">
			var qty = new LiveValidation(\''.$arrCartItem[NAME].'\');
			qty.add( Validate.Numericality, { maximum: '.$arrCartItem[STOCK].' } );
			</script>
			
			</td>
         <td align="center">'.$arrCartItem[STOCK].'</td>
         <td align="center">$'.$arrCartItem[PRICE].'</td>
         <td align="center">$'.$total.'</td>
			<td>
				<table>
				<tr><td><input type="image" src="images/button_update.png" /></td></tr>
				</table>	
				</td>			
         </tr>';
			
			$pSubTotal += $total;
}

function renderCombo($arrItem,$pName,$pValue,$pDisplay, $pSelected = null)        //a array with id, and name index
{
	
    $cmb = '<select name="'.$pName.'" id="'.$pName.'" class="cmb">
			<option value ="">Select</option>';
    for($i=0; $i<count($arrItem); $i++)
    {
		$selected = ($arrItem[$i][$pValue] == $pSelected) ? 'selected="selected"' : '';
        $cmb .= '<option value="'.$arrItem[$i][$pValue].'" '.$selected.'>'.$arrItem[$i][$pDisplay].'</option>';
    }
   
    $cmb .= '</select>';
	
	return $cmb;

}


function renderCartIteminCheckout($arrCartItem,$pImage, $pShipping, &$pSubTotal)
{
	
   $total = round((($arrCartItem[QUANTITY] * $arrCartItem[PRICE])+$pShipping),2);
	$url = "processing/stores_processing.php?act=del&amp;cartid=$arrCartItem[ID]";
	echo '<tr>
         <td align="center"><img src="productimages/thumb/'.$pImage.'" alt="'.$arrCartItem[NAME].'" /></td>
         <td align="center">'.$arrCartItem[NAME].'</td>
         <td align="center">'.$arrCartItem[QUANTITY].'</td>
         <td align="center">'.$arrCartItem[STOCK].'</td>
         <td align="center">$'.$arrCartItem[PRICE].'</td>
			<td align="center">$'.$pShipping.'</td>
         <td align="center">$'.$total.'</td>
			<td></td>
							
         </tr>';
			
			$pSubTotal += $total;
}
function renderNoItemInCart()
{
	$html = '<div class="centerBox">
		  	 <div class="Top"></div>
	    	 <div class="Center">No Item In Cart</div>
		  	 <div class="Bottom"></div>
			 </div>';
			 
	echo $html;
}

function renderTopCheckout($pProcess)
{

	$img1 = ($pProcess == 1) ? 'images/co_process1_on.png' : 'images/co_process1_off.png';
	$img2 = ($pProcess == 2) ? 'images/co_process2_on.png' : 'images/co_process2_off.png';
	$img3 = ($pProcess == 3) ? 'images/co_process3_on.png' : 'images/co_process3_off.png';
	
	
	$html =  '<table>
				<tr>
					<td></td>
					<td><a href="?process=1"><img border=0 src="'.$img1.'" /></a></td>
					<td width="160"></td>
					<td><a href="?process=2"><img border=0 src="'.$img2.'" /></a></td>
					<td width="160"></td>
					<td><a href="?process=3"><img border=0 src="'.$img3.'" /></a></td>
					<td></td>
				</tr>
		   	</table>';
				
	echo $html;
			
}


function renderTopFeedback($pStoreName)
{
	//echo $pStoreName;
	$html =  '<table>
				<tr>
					<td width="75"></td>
					<td><input type="radio" name="level" value="P" onclick="feedbackFilter(this.value,'.CN_S($pStoreName).')" />
					<img border=0 src="'.placeLevelImage('P').'" />
					<td>Positive:&nbsp;</td>
					</td>
					<td width="160"></td>
					<td><input type="radio" name="level" value="N" onclick="feedbackFilter(this.value,'.CN_S($pStoreName).')" />
					<img border=0 src="'.placeLevelImage('N').'" />
					<td>Neutral:&nbsp;</td>
					</td>
					<td width="160"></td>
					<td><input type="radio" name="level" value="Ng" onclick="feedbackFilter(this.value,'.CN_S($pStoreName).')" />
					<img border=0 src="'.placeLevelImage('Ng').'" />
					<td>Negative:&nbsp;</td>
					</td>
					<td></td>
				</tr>
		   	</table>';
				
	echo $html;
			
}

function renderBuyerInfoinCheckout($pRowBuyer)
{
	$html = '<div class="global_heading">Confirm your Shipping Information</div><br />
      If you want to make any change in your shipping info, please go you <a href="member_account.php">Account</a> and return again.<br /><br />
      
      <table>
      <tr>
      <td>&nbsp;</td>
      <td><strong>FULL NAME:</strong></td><td>&nbsp;</td><td>'. $pRowBuyer[FIRSTNAME].' '.$pRowBuyer[LASTNAME].'</td>
      <td>&nbsp;</td>
      </tr>
      
      <tr>
      <td>&nbsp;</td>
      <td><strong>ADDRESS:</strong></td><td>&nbsp;</td><td>'. $pRowBuyer[ADDRESS].'</td>
      <td>&nbsp;</td>
      </tr>
      
      <tr>
      <td>&nbsp;</td>
      <td><strong>POST OFFICE ADDRESS:</strong></td><td>&nbsp;</td><td>'. $pRowBuyer[POADDRESS].'</td>
      <td>&nbsp;</td>
      </tr>
      
      <tr>
      <td>&nbsp;</td>
      <td><strong>COUNTRY:</strong></td><td>&nbsp;</td><td>'. $pRowBuyer[COUNTRYNAME].'</td>
      <td>&nbsp;</td>
      </tr>
      
      <tr>
      <td>&nbsp;</td>
      <td><strong>CITY:</strong></td><td>&nbsp;</td><td>'. $pRowBuyer[CITY].'</td>
      <td>&nbsp;</td>
      </tr>
      
      <tr>
      <td>&nbsp;</td>
      <td><strong>STATE:</strong></td><td>&nbsp;</td><td>'. $pRowBuyer[STATENAME].'</td>
      <td>&nbsp;</td>
      </tr>
      
      <tr>
      <td>&nbsp;</td>
      <td><strong>PROVINCE:</strong></td><td>&nbsp;</td><td>'. $pRowBuyer[PROVINCE].'</td>
      <td>&nbsp;</td>
      </tr>
      
      <tr>
      <td>&nbsp;</td>
      <td><strong>ZIP CODE:</strong></td><td>&nbsp;</td><td>'. $pRowBuyer[ZIPCODE].'
      &nbsp;&nbsp;&nbsp;<strong>EXT:</strong>&nbsp;'. $pRowBuyer[ZIPEXT].'</td>
      <td>&nbsp;</td>
      </tr>
      
      <tr>
      <td>&nbsp;</td>
      <td><strong>PHONE NUMBER:</strong></td><td>&nbsp;</td><td>'. $pRowBuyer[PHONENUMBER].'</td>
      <td>&nbsp;</td>
      </tr>
      
      <tr>
      <td>&nbsp;</td>
      <td><strong>FAX NUMBER:</strong></td><td>&nbsp;</td><td>'. $pRowBuyer[FAXNUMBER].'</td>
      <td>&nbsp;</td>
      </tr>
      
      <tr>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td>&nbsp;</td>
      <td><a href="checkout.php?process=2"><img border="0" src="images/next.png" /></a></td>
      </tr>
      </table>';
		
		echo $html;
}

function renderMailGrid($pType, $arrMails)
{
		  
echo '<table border=0 width=700>';

	switch($pType)
	{
		case 'sent':	
		
			//print_r($arrMails);
			echo '
					<tr bgcolor="#FFFF99">
						<th width="120">To</th>
						<th width="252">Subject</th>
						<th width="150">Date</th>
						<th width="50">Is Important</th>
						<th width="50">Delete</th>
				  </tr>';
		
		  for($i=0; $i<count($arrMails); $i++)
		  {
		  
		  $urlDel = 'processing/member_account_processing.php?act=delmail_s&id='.$arrMails[$i][ID];
		  
		  if($arrMails[$i][ISIMPORTANT_S])
			{
				$important ='No';
				$url = 'processing/member_account_processing.php?act=imps&id='.$arrMails[$i][ID].'&set=0';
	   	}else
			{
				$important ='Yes';
				$url = 'processing/member_account_processing.php?act=imps&id='.$arrMails[$i][ID].'&set=1';
			}
			
		  		echo '<tr bgcolor="#FFFF44">';
				echo '<td><a href="?act=mail&id='.$arrMails[$i][ID].'&cmd=read">'.$arrMails[$i][SENTTO].'</a></td>';
				echo '<td><a href="?act=mail&id='.$arrMails[$i][ID].'&cmd=read">'.fixLengthWords($arrMails[$i][SUBJECT],6).'</a></td>';
				echo '<td>'.$arrMails[$i][SENTDATE].'</td>';
				echo '<td align="center"><a href="'.$url.'">'.$important.'</a></td>';
				echo '<td align="center"><a href="" onclick="javascript:return false;">
						<img src="images/del_small.png" border=0 onClick="confirmation(\''.$urlDel.'\')"/></a></td>';
				echo '</tr>';
		  }
		break;
		
		
		case 'inbox':	
		
			//print_r($arrMails);
			echo '
					<tr bgcolor="#FFFF99">
						<th width="120">From</th>
						<th width="252">Subject</th>
						<th width="150">Date</th>
						<th width="50">Is Important</th>
						<th width="50">Delete</th>
				  </tr>';
		
		  for($i=0; $i<count($arrMails); $i++)
		  {
		  
		  $urlDel = 'processing/member_account_processing.php?act=delmail_r&id='.$arrMails[$i][ID];
		  
		  	if($arrMails[$i][ISREAD])
			{
				$from = $arrMails[$i][SENTBY];
	   		$subject = $arrMails[$i][SUBJECT];
			}
			else
			{
				$from = '<strong>'.$arrMails[$i][SENTBY].'</strong>';
	   		$subject = '<strong>'.$arrMails[$i][SUBJECT].'</strong>';
			}
			
			if($arrMails[$i][ISIMPORTANT_R])
			{
				$important ='No';
				$url = 'processing/member_account_processing.php?act=impr&id='.$arrMails[$i][ID].'&set=0';
	   	}else
			{
				$important ='Yes';
				$url = 'processing/member_account_processing.php?act=impr&id='.$arrMails[$i][ID].'&set=1';
			}
			
			//Checking whether it is deleted by user or not
		  		echo '<tr bgcolor="#FFFF44">';
				echo '<td><a href="?act=mail&id='.$arrMails[$i][ID].'&cmd=read">'.$from.'</a></td>';
				echo '<td><a href="?act=mail&id='.$arrMails[$i][ID].'&cmd=read">'.fixLengthWords($arrMails[$i][SUBJECT],6).'</a></td>';
				echo '<td>'.$arrMails[$i][SENTDATE].'</td>';
				echo '<td align="center"><a href="'.$url.'">'.$important.'</a></td>';
				echo '<td align="center"><a href="" onclick="javascript:return false;">
						<img src="images/del_small.png" border=0 onClick="confirmation(\''.$urlDel.'\')"/></a></td>';
				echo '</tr>';

		  }
		break;
		
		
		case 'importantr':	
		
			//print_r($arrMails);
			echo '
					<tr>
						<th width="120">From</th>
						<th width="252">Subject</th>
						<th width="150">Date</th>
						<th width="50">Is Important</th>
				  </tr>';
		
		  for($i=0; $i<count($arrMails); $i++)
		  {
		  	
			if($arrMails[$i][ISIMPORTANT_R])
			{
				$important ='No';
				$url = 'processing/member_account_processing.php?act=impr&id='.$arrMails[$i][ID].'&set=0';
	   	}else
			{
				$important ='Yes';
				$url = 'processing/member_account_processing.php?act=impr&id='.$arrMails[$i][ID].'&set=1';
			}
			
		  		echo '<tr>';
				echo '<td><a href="?act=mail&id='.$arrMails[$i][ID].'&cmd=read">'.$arrMails[$i][SENTBY].'</a></td>';
				echo '<td><a href="?act=mail&id='.$arrMails[$i][ID].'&cmd=read">'.fixLengthWords($arrMails[$i][SUBJECT],6).'</a></td>';
				echo '<td>'.$arrMails[$i][SENTDATE].'</td>';
				echo '<td align="center"><a href="'.$url.'">'.$important.'</a></td>';
				echo '</tr>';
		  }
		break;
		
		
		case 'importants':	
		
			//print_r($arrMails);
			echo '
					<tr>
						<th width="120">To</th>
						<th width="252">Subject</th>
						<th width="150">Date</th>
						<th width="50">Is Important</th>
				  </tr>';
		
		  for($i=0; $i<count($arrMails); $i++)
		  {
		  
		  if($arrMails[$i][ISIMPORTANT_S])
			{
				$important ='No';
				$url = 'processing/member_account_processing.php?act=imps&id='.$arrMails[$i][ID].'&set=0';
	   	}else
			{
				$important ='Yes';
				$url = 'processing/member_account_processing.php?act=imps&id='.$arrMails[$i][ID].'&set=1';
			}
		  	
		  		echo '<tr>';
				echo '<td><a href="?act=mail&id='.$arrMails[$i][ID].'&cmd=read">'.$arrMails[$i][SENTTO].'</a></td>';
				echo '<td><a href="?act=mail&id='.$arrMails[$i][ID].'&cmd=read">'.fixLengthWords($arrMails[$i][SUBJECT],6).'</a></td>';
				echo '<td>'.$arrMails[$i][SENTDATE].'</td>';
				echo '<td align="center"><a href="'.$url.'">'.$important.'</a></td>';
				echo '</tr>';
		  }
		break;

		
	}
		  
echo '</table>';
}


function renderEmailMessage($pRowEmail)
{
	echo '<table width="650">';
	
	echo '<tr><td><strong>'.$pRowEmail[SUBJECT].'</strong>&nbsp;to <strong>'.$pRowEmail[SENTTO].'</strong></td></tr>';
	echo '<tr><td><strong>From: </strong>'.$pRowEmail[SENTBY].'</td></tr>';
	echo '<tr><td>'.US_DateTime($pRowEmail[SENTDATE]).'</td></tr>';
	echo '<tr><td><hr /></td></tr>';
	echo '<tr><td>'.$pRowEmail[MESSAGE].'</td></tr>';
	
	echo '<tr><td></td></tr>';
	echo '<tr><td>
			<a href="?act=mail&id='.$pRowEmail[ID].'&cmd=reply&to='.$pRowEmail[SENTBY].'&subject='.$pRowEmail[SUBJECT].'">Reply</a>
			</td></tr>';
	
	echo '</table>';
}

function renderPackagePayment($pAmount,$pAdminPaypalEmail)
{
	echo '<form action="https://www.sandbox.paypal.com/cgi-bin/webscr" method="post" name="paypal"
	 	     enctype="application/x-www-form-urlencoded">
	<input type="hidden" name="cmd" value="_xclick">  
  <input type="hidden" name="return" value="'.SITEURL.'processing/packagefee_paid.php?act=done">  
  <input type="hidden" name="business" value="'.$pAdminPaypalEmail.'">
  <input type="hidden" name="return" value="'.SITEURL.'thanks.php">  
  <input type="hidden" name="notify_url" value="'.SITEURL.'processing/package_paid.php?token='.session_id().'"> 
    
 <input type="hidden" name="item_name" value="Package Fee">  
 <input type="hidden" name="amount" value="'.$pAmount.'">  

 <input type="image" src="https://www.paypal.com/en_US/i/btn/btn_xpressCheckout.gif" />

</form>';
}

function renderFeedback($pStoreID, $pItemID, $pGivenBy, $pFeedback)
{
	$P = ($pFeedback[COMMENTLEVEL] == 'P') ? 'checked="checked"' : '';
	$N = ($pFeedback[COMMENTLEVEL] == 'N') ? 'checked="checked"' : '';
	$Ng = ($pFeedback[COMMENTLEVEL] == 'Ng') ? 'checked="checked"' : '';
	
	
	echo '<table width="100%" border="0">
               <form method="post" action="processing/stores_processing.php?act=feedback">
               <input type="hidden" name="givenby" value="'.$pGivenBy.'" />
               <input type="hidden" name="storeid" value="'.$pStoreID.'" />
               <input type="hidden" name="itemid" value="'.$pItemID.'" />
					<input type="hidden" name="page" value="home" />
					
                 <tr align="center" style="font:verdana">
                   <td  ><textarea name="comments" rows="4" cols="19">'.$pFeedback[COMMENTS].'</textarea> </td>
                 </tr>
                 
                 
                 <tr align="center" style="font:verdana">
                   <td>
                   <table width="100%" border="0">
                      <tr>
                         <td width="10">&nbsp;</td>
                       <td width="331"><input name="commentlevel" type="radio" value="P" '.$P.' />
								 	  <img src="images/icon_positive.gif" alt="Positive" />
                         </td>
                       <td width="319"><input type="radio" name="commentlevel" value="N" '.$N.' />
								 	  <img src="images/icon_neutral.gif" alt="Neutral" />
                         </td>
                         <td width="276"><input type="radio" name="commentlevel" value="Ng" '.$Ng.' />
								 	  <img src="images/icon_negative.gif" alt="Nagative" />
                         </td>
                         <td width="49">&nbsp;</td>
                     </tr>
						</table>
                  
                   </td>
                 </tr>';
                 
					  
		  if($pFeedback == '')
		  {
				echo	'<tr align="center" style="font:verdana">
						 <td><input type="submit" value="Submit" /></td>
						 </tr>';
		 }
		 else
		 {
				echo	'<tr align="center" style="font:verdana">
						 <td>YOU HAVE ALREADY GIVE FEEDBACK AGAINST THIS ITEM.</td>
						 </tr>';

		 			
		 }
      
			echo  '</form>
					</table>';
			
}

function renderOrderStatus($pStatus, $pOrderNumber)
{
	if($pStatus == 'PENDING')
		$P = 'checked = "checked"';
	else
		$D = 'checked = "checked"';
	
	/*echo '<br />P '.$P;
	echo '<br />D '.$D;*/
	
	$html = '<input name="'.$pOrderNumber.'" type="radio" '.$P.' value="PENDING" 
										onclick="setOrderStatus(this.value,\''.$pOrderNumber.'\')" />Pending';
										
	$html .= '<input name="'.$pOrderNumber.'" type="radio" '.$D.' value="DELIVERED" 
										onclick="setOrderStatus(this.value,\''.$pOrderNumber.'\')" />Delivered';
										
	return $html;

}

function renderRateSlider()
{
	echo
		'<label for="amount">Rate:</label>
		<input type="text" id="amount" style="border:0; color:#f6931f; font-weight:bold;" onChange="rate(this.value)" />
			
		<div id="slider-vertical" style="width:250px;"></div>';

}


//============================================= URLS MAKER ==================================================== 
function fullURL($path)
{
	return SITEURL.$path;
}
function urlRegister()
{
	return 'register.php?act=buyer';
}
function urlLogin()
{
	return SITEURL.'login.php';
}
function urlLogout()
{
	return SITEURL.'processing/login_processing.php?act=logout';
}
function urlCart()
{
	return SITEURL.'cart.php';
}
function urlAddtoCartFeaturedItem($pStoreID,$pItemID)
{
	return SITEURL.'processing/stores_processing.php?act=addtocart&itemid='.$pItemID.'&storeid='.$pStoreID;
}
function urlGlobalCategory($pGlobalCatName)
{
	$pGlobalCatName = str_ireplace(' ', '_', $pGlobalCatName);
	return SITEURL.'global/'.$pGlobalCatName;
	//return SITEURL.'global.php?gcid='.$pGlobalCatID;
}
function urlSubGlobalCategory($pSubGlobalCatName)
{
	$pSubGlobalCatName = str_ireplace(' ', '_', $pSubGlobalCatName);
	return SITEURL.'global/sub/'.$pSubGlobalCatName;
	//return SITEURL.'global.php?sgcid='.$pSubGlobalCatID;
}
function urlCategory($pStoreName, $pCategoryName)
{
	//return 'store_category.php?cid='.$pCatID;
	$pCategoryName = str_ireplace(' ', '_', $pCategoryName);
	return 'http://'.$pStoreName.HOSTNAME.'/category/'.$pCategoryName;
}
function urlSubCategory($pStoreName, $pSubCateName)
{
	//return 'store_category.php?scid='.$pSubCatID;
	$pSubCateName = str_ireplace(' ', '_', $pSubCateName);
	return 'http://'.$pStoreName.HOSTNAME.'/category/sub/'.$pSubCateName;
}

function profileURL($pStoreID)
{
	return SITEURL.'profile.php?storeid='.$pStoreID;
}

function feedbackURL($pStoreID)
{
	return SITEURL.'feedback.php?storeid='.$pStoreID.'&filter=';
}
/*function urlItemDetail($pItemName, $pStoreName = null)
{
	$pItemName = str_ireplace(' ', '_', $pItemName);
	//return SITEURL.'stores.php?storeid='.$pStoreID.'&itemid='.$pItemID.'&page=itemdetail';
	return 'http://'.$pStoreName.HOSTNAME.'/products/'.$pItemName;
}*/

function urlItemDetail($pItemID, $pStoreID)
{
	return SITEURL.'itemdetail.php?itemid='.$pItemID;
}

function urlRSS($pStoreID)
{
	return SITEURL.'RSS/?storeid='.$pStoreID;
}

function urlStore($pStoreID)
{
	return SITEURL.'shop.php?storeid='.$pStoreID;
	//return 'http://'.$pStoreName.HOSTNAME;
}
function urlProfile($pMemID)
{
	return SITEURL.'profile.php?storeid='.$pMemID;
	//return 'http://'.$pStoreName.HOSTNAME;
}
function urlHomeMVM()
{
	return SITEURL;
}
function urlPaypalReturn()
{
	return SITEURL.'processing/_xorder_paid.php';
}
function urlFeedback($pStoreName)
{
	return SITEURL.'feedbacks/'.$pStoreName;
}
function loadPage_greybox($pUrl, $pCaption)
{
	/*echo 'URL '.$pUrl.'<br />';
	echo 'Caption '.$pCaption.'<br />';*/
	
	echo '<a href="'.$pUrl.'" title="'.$pCaption.'" rel="gb_page[450, 500]">
			'.$pCaption.'</a>';
}
//============================================= [ENDS ]URLS MAKER ==================================================== 

function makePageTitle($page, $param = null)
{
	$title = null;
	switch($page)
	{
		case 'aboutus':
			$title = 'About Us';
		break;
		
		case 'register':
			$title = 'Registration';
		break;
		
		default:
			$title = 'Multi Vendor Mall';
		break;
	}
	
	return $title;
}

		
function makeKeywords($pWord)
{
	$arrWord = explode(' ',$pWord);
	//print_r($arrWord);
	foreach($arrWord as $word)
	{
		$link = '<a href="search_item.php?item='.$word.'">'.$word.'</a>';
		echo $link.' ';
	}
		
}
function redirectToError()
{
	header("Location: ".SITEURL."error_page.php");
}
function placeLevelImage($pLevel)
{
	if($pLevel == 'P')
	{
		$src = 'P.gif';
	}
	elseif($pLevel == 'N')
	{
		$src = 'N.gif';
	}else
	{
		$src = 'Ng.gif';
	}
	
	return fullURL('iconset/'.$src);

}
function topLeftNav_NoLogin()
{
	$html = '<table style="font-size:11px"><tr>
				<td>'.createImageLink('up_16.png', fullURL('register.php?act=buyer'), 'Signup').'</td>
				<td align="center">&nbsp;|&nbsp;'.createImageLink('key_16.png', urlLogin(), 'Login').'</td>
				<td>&nbsp;|&nbsp;'.createImageLink('buy_16.png', fullURL('all_sellers.php'), 'Buy').'</td>
				<td>&nbsp;|&nbsp;'.createImageLink('help_16.png',fullURL('index.php?page=faqs'), 'FAQs').'</td>
				<td>&nbsp;|&nbsp;'.createImageLink('home_16.png', urlHomeMVM(), 'Home').'</td>
				</tr></table>';
				
	return $html;
}
function topLeftNav_Login($pNewMessages)
{
	//check if new mail in inbox
	//echo 'New msgs '.$pNewMessages;
	$myAccount = ($pNewMessages > 0) ? 'My Account ['.$pNewMessages.']' : 'My Account';
	
	$html = '<table><tr>
				<td>Hi '.$_COOKIE['username'].'&nbsp;|</td>
				<td>&nbsp;'.createImageLink('key_16.png', urlLogout(), 'Logout').'</td>
				<td>&nbsp;|&nbsp;'.createImageLink('account_16.png', fullURL('member_account.php'), $myAccount).'</td>
				<td>&nbsp;|&nbsp;'.createImageLink('buy_16.png', fullURL('all_sellers.php'), 'Buy').'</td>
				<td>&nbsp;|&nbsp;'.createImageLink('help_16.png',fullURL('index.php?page=faqs'), 'FAQs').'</td>
				<td>&nbsp;|&nbsp;'.createImageLink('home_16.png', urlHomeMVM(), 'Home').'</td>
				</tr></table>';
				
	return $html;
}
																																				

function redirecttoHome()
{
	header("Location: ".SITEURL."index.php");
}														


function v($pCap, $pString, $pType = 'String', $pString2 = null)
{
	if($pType == 'email')
	{
		if($pString == '' or !isValidEmail($pString) or !isMatched($pString, $pString2))	
		{
			$_SESSION[v] .= $pCap.' cannot be Null and Must be Email and Must be matched<br />';	
		}
	}
	elseif($pType == 'password')
	{
		if($pString == '' or !isMatched($pString, $pString2))	
		{
			$_SESSION[v] .= $pCap.' cannot be Null and Must be Matched<br />';	
		}
	}
	elseif($pType == 'number')
	{
		if($pString == '' or !isNumber($pString))	
		{
			$_SESSION[v] .= $pCap.' cannot be Null and Must be Integer/Number<br />';	
		}
	}
	elseif($pType == 'integer')
	{
		if($pString == '' or !isInteger($pString))	
		{
			$_SESSION[v] .= $pCap.' cannot be Null and Must be Integer/Number<br />';	
		}
	}
	else
	{
		if($pString == '')
		{
			$_SESSION[v] .= $pCap.' cannot be Null<br />';	
		}
	}
}



function isValidEmail($email){
      $pattern = "^[_a-z0-9-]+(\.[_a-z0-9-]+)*@[a-z0-9-]+(\.[a-z0-9-]+)*(\.[a-z]{2,3})$";
     
      if (eregi($pattern, $email)){
         return true;
      }
      else {
         return false;
      }   
   }
	
function isMatched($p1, $p2)
{
	if(strcmp($p1, $p2) == 0)
		return true;
	else
		return false;
}

function isInteger($pInteger)
{
	if(ctype_digit($pInteger) == 1)
		return true;
	else
		return false;
}

function isNumber($pNumber)
{
	if(is_numeric($pNumber))
		return true;
	else
		return false;
}
?>